<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var largestDivisibleSubset = function (nums) {
      nums.sort((a, b) => a - b)
      let dp = [[nums[0]]]
      let res = dp[0]
      console.log([[nums[0]]]);
      for (let i = 1; i < nums.length; i++) {
        dp[i] = [nums[i]]

        for (let j = 0; j < i; j++) {
          if (nums[i] % nums[j] === 0 || nums[j] % nums[i] == 0) {
            dp[i] = [...dp[j], nums[i]]
            // console.log(nums[i]);
          }
        }
        if (dp[i].length > res.length) {
          res = dp[i]
        }
      }
      return res
    };
    console.log(largestDivisibleSubset([1, 2, 3]));
  </script>
</body>

</html>